package com.xsm.ppsecret;

import android.app.Application;

import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.xsm.ppsecret.config.Authority;
import com.xsm.ppsecret.config.Constants;
import com.xsm.ppsecret.util.EaseHelper;
import com.xsm.ppsecret.util.ShareManager;

/**
 * Author: Xiasem
 * Email: xiasem@163.com
 * Date: 17-2-10.
 */

public class App extends Application {

    private static App instance;
    public int authority = Authority.NULL;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        ShareManager.init(this);

        EaseHelper.getInstance().init(this);
        if (!ShareManager.getInstance().isFirstUseChat()) {
            loginEM();
        }
    }

    public static App getInstance() {
        return instance;
    }

    private void loginEM() {
        ShareManager shareManager = ShareManager.getInstance();
        EMClient.getInstance().login(shareManager.getUsername(), shareManager.getUsername(), new EMCallBack() {
            @Override
            public void onSuccess() {
                EMClient emClient = EMClient.getInstance();
                emClient.groupManager().loadAllGroups();
                emClient.chatManager().loadAllConversations();
            }

            @Override
            public void onError(int i, String s) {

            }

            @Override
            public void onProgress(int i, String s) {

            }
        });
    }
}
